<template>
	<view class="container">
		<view class="container-c">
			<image class="logo" src="/static/icons/leju-logo.png" mode=""></image>
			<form @submit="formSubmit">
				<view class="ipt">
					<input type="text" value="17596496508" name="username" />
					<input class="pwd" type="password" value="123456" name="password" />
					<button class="login" form-type="submit" type="default">登录</button>
				</view>
			</form>
			<view class="bottom">
				<text>找回密码</text>
				<text class="line"></text>
				<text @tap="doRegister">注册账号</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		doLogin
	} from "@/api/user/login/index.js";
	import {getMemberInfo} from "@/api/user/login/index.js"
	export default {
		data() {
			return {
				username: "",
				password: ""
			};
		},
		methods: {
			doRegister() {
				uni.navigateTo({
					url: "/pages/mine/register/register"
				})
			},
			// 提交登录表单
			formSubmit(e){
				var userInfo=e.detail.value;
				// console.log(userInfo)
				uni.removeStorageSync("token")
				doLogin({
					username: userInfo.username,
					password: userInfo.password
				}).then(res => {
					console.log(res)
					if(res.success==true){						
						getMemberInfo({							
						}).then(res=>{
							console.log(res)
							var users=res.data.userInfo;
							uni.setStorageSync("userInfo",users)
						})
						uni.setStorageSync("token", res.data.token);
						uni.showToast({
							title: "登录成功,1秒后跳转到个人中心",
							icon:"none"
						})
						setTimeout(() => {
							uni.switchTab({
								url: "/pages/mine/mine"
							})
						}, 1000)
					}else if(res.success==false){
						uni.showToast({
							title: res.message
						})
					}
					
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		background-color: #f1ece7;
		height: 100vh;
	}

	.container-c {
		width: 614rpx;
		margin: 0 auto;
	}

	.logo {
		display: block;
		width: 160rpx;
		height: 160rpx;
		border-radius: 50%;
		margin: 0 auto;
	}

	.ipt {
		margin-top: 186rpx;
		margin-bottom: 50rpx;

		input,
			{
			height: 36rpx;
			color: #333;
			margin-top: 64rpx;
			padding: 32rpx 64rpx;
			border-radius: 100rpx;
			box-shadow: 0 0 60rpx rgba(0, 0, 0, .1);
		}

		.login {
			margin-top: 120rpx;
			background-color: #354e44;
			color: #fff;
			text-align: center;
			line-height: 68rpx;
			padding: 16rpx;
			border-radius: 100rpx;
			box-shadow: 0 0 60rpx rgba(0, 0, 0, .1);
		}
	}

	.bottom {
		width: 50%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 0 auto;

		.line {
			display: inline-block;
			width: 6rpx;
			height: 32rpx;
			background-color: rgba(0, 0, 0, .7);
			;
		}
	}
</style>
